package com.leyou.cart.controller;

import com.leyou.cart.entity.Cart;
import com.leyou.cart.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: xiang
 * @Date: 2019/9/1 20:42
 * @Description:
 */
@RestController
@RequestMapping
public class CartController {
    @Autowired
    private CartService cartService;
    /**
     *添加购物车
     */
    @PostMapping
    public ResponseEntity<Void> addCart(@RequestBody Cart cart){
        cartService.addCart(cart);
        return ResponseEntity.ok().build();

    }
    /**
     * 查询购物车列表
     */
    @GetMapping("list")
    public ResponseEntity<List<Cart>> queryCartList(){
        List<Cart>  cartList=cartService.queryCartList();
        return ResponseEntity.ok(cartList);



    }

    /**
     * 批量新增购物车
     * @return
     */
    @PostMapping("list")
    public ResponseEntity<Void>  addCartList(@RequestBody List<Cart> cartList){
        cartService.addCartList(cartList);
        return ResponseEntity.ok().build();

    }


}